1777B - Emordnilap - CodeForces Solution


greedy math

Please click on ads to support us..

C++ Code:

#include <bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
//using namespace __gnu_pbds;
using namespace std;
#define fio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define op1(x,y) cout<<"Case #"<<x<<": "<<y<<endl
#define lb(a,val) lower_bound(a.begin(),a.end(),val)
#define ub(a,val) upper_bound(a.begin(),a.end(),val)
#define mem(a,b) memset(a,b,sizeof(a))
#define rf(m,a) for(ll i=m;i>=a;i--)
#define ftt ll t;cin>>t;while(t--)
#define f(k,m) for(ll i=k;i<m;i++)
#define INF 9223372036854775807
#define dbg cout<<"hii"<<endl;
#define ya cout<<"YES"<<endl
#define na cout<<"NO"<<endl
#define op(n) cout<<n<<endl;
#define ll long long int
#define nl cout<<endl;
#define MAXN 20000000
#define mod 1000000007
#define mp make_pair
#define pb push_back
#define sp <<" "<<
#define ss second
#define ff first

void foo(ll fact[])
{
    fact[0]=1;
    fact[1]=1;
    for(ll i=2;i<100001;i++)
    {
        fact[i] = fact[i-1]*i;
        fact[i]%=mod;
    }

}


int main()
{
    ll fact[100001];
    ll n,ans;
    foo(fact);
    ll t;
    cin>>t;
    while(t--)
    {
        cin>>n;
        ans = fact[n];
        ans*=n;
        ans%=mod;
        ans*=(n-1);
        ans%=mod;
        cout<<ans;nl;
    }
    return 0;
}


Comments

Submit
0 Comments
More Questions

149A - Business trip
34A - Reconnaissance 2
59A - Word
462B - Appleman and Card Game
1560C - Infinity Table
1605C - Dominant Character
1399A - Remove Smallest
208A - Dubstep
1581A - CQXYM Count Permutations
337A - Puzzles
495A - Digital Counter
796A - Buying A House
67A - Partial Teacher
116A - Tram
1472B - Fair Division
1281C - Cut and Paste
141A - Amusing Joke
112A - Petya and Strings
677A - Vanya and Fence
1621A - Stable Arrangement of Rooks
472A - Design Tutorial Learn from Math
1368A - C+=
450A - Jzzhu and Children
546A - Soldier and Bananas
32B - Borze
1651B - Prove Him Wrong
381A - Sereja and Dima
41A - Translation
1559A - Mocha and Math
832A - Sasha and Sticks